<?php

$test = 0;

$plugin['version'] = '0.1';
$plugin['author'] = 'Mykhailo Kotsur';
$plugin['author_uri'] = 'http://sotomajor.org.ua/';
$plugin['description'] = 'Allows to embed your smug-mug thumbnails into your web-site';

// Plugin types:
// 0 = regular plugin; loaded on the public web side only
// 1 = admin plugin; loaded on both the public and admin side
// 2 = library; loaded only when include_plugin() or require_plugin() is called
$plugin['type'] = 0;


@include_once('zem_tpl.php');

if (0) {
?>
# --- BEGIN PLUGIN HELP ---

h1. str_smug_random_thumb  login

# --- END PLUGIN HELP ---
<?php
}

# --- BEGIN PLUGIN CODE ---

if ($test !== 1) {
    global $txpcfg;
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/phpSmug/phpSmug.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMug.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMugEntity.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMugAlbum.php');
    require_once($txpcfg['txpath'].'/include/str_smugplug_lib/str_SmugMugImage.php');
} else {
    require_once('str_smugplug_lib/phpSmug/phpSmug.php');
    require_once('str_smugplug_lib/str_SmugMug.php');
    require_once('str_smugplug_lib/str_SmugMugEntity.php');
    require_once('str_smugplug_lib/str_SmugMugAlbum.php');
    require_once('str_smugplug_lib/str_SmugMugImage.php');
}

function str_smug_random_thumb($params) {
	extract($params, EXTR_PREFIX_ALL, 'param');
	
	if (empty($param_login)) {
		return false;
	}
	
	$smugMug = new str_SmugMug($param_login);
	return $smugMug->getRandomAlbum()->getRandomImage()->getTinyUrl();
}

function str_smug_latest_albums_thumbs($params) {
	extract($params, EXTR_PREFIX_ALL, 'param');
	
	if (empty($param_login)) {
		return false;
	}
    
    if (empty($param_count) || ((int)$param_count > 0 === false)) {
        $param_count = 5;
    }
    
    $smugMug = new str_SmugMug($param_login);
    $albums = $smugMug->getAlbumList();
    $links = array();
    for($i = 0; $i < $param_count; $i++) {
        $image = $albums[$i]->getRandomImage();
        $links[] = '<a href="' . $image->getInAlbumUrl() . '" title="' . $image->getLinkTitle() . '">
                        <img src="' . $image->getTinyUrl() . '" alt="' . $image->getLinkTitle() . '"/>
                    </a>';
    }
    
    return implode("\n", $links);
}


# --- END PLUGIN CODE ---
if ($test === 1) {
    echo str_smug_latest_albums_thumbs(array('login' => 'sotomajor'));
}
